<template>
	<view class="show-search-content">
		<view class="tip">
			搜索结果共有 {{searchList.length}} 个
		</view>
		<uni-list>
		    <uni-list-item v-for="(v, i) in searchList" :key="v.id"
				:title="'玩家: ' + v.playerName" 
				:note="'ID: ' + v.id" 
				:rightText="(i + 1) + ''"
				:clickable="true"
				:to="'ShowPlayerInfo?playerName=' + v.playerName + '&playerId=' + v.id"></uni-list-item>
		</uni-list>
		<uni-pagination title="分页" show-icon="true" 
			:total="searchList.length" 
			:pageSize="10"
			:current="curPage"
			@change="pageChange"></uni-pagination>
	</view>
</template>

<script>
	import {uniList} from '@dcloudio/uni-ui'
	import {uniListItem, uniPagination} from '@dcloudio/uni-ui'
	import ajax from '../../../Ajax/index.js'
	export default {
		components: {
			uniList,
			uniListItem,
			uniPagination
		},
		data() {
			return {
				pageList: [],
				searchList: [],
				curPage: 1,
				searchKeyword: ''
			}
		},
		onLoad(e) {
			console.log(e);
			this.searchKeyword = e.searchKeyword
			if(this.searchKeyword == undefined || this.searchKeyword == '') {
				uni.showToast({title: '搜索关键词为空', icon: 'none'})
				return
			}
			this.getSearchContent()
		},
		methods: {
			getSearchContent() {
				let param = new URLSearchParams()
				param.append("search", this.searchKeyword)
				ajax.post('account/searchPlayer', param).then(res => {
					if(res.data.code == 200) {
						this.searchList = res.data.list
						this.pageChange({current: 1})
						console.log(231);
					}
				})
			},
			pageChange(v) {
				this.curPage = v.current
				let index = (this.curPage - 1)
				if(index * 10 + 8 < this.searchList.length) {
					this.pageList = this.searchList.slice(index * 10, index * 10 + 10)
				} else {
					this.pageList = this.searchList.slice(index * 10);
				}
			},
			itemClick(playerName, playerId) {
				uni.navigateTo({
					url: 'ShowPlayerInfo?playerName=' + playerName + '&playerId=' + playerId
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.show-search-content {
		.tip {
			width: 100%;
			height: 60rpx;
			text-align: center;
			line-height: 60rpx;
		}
	}
</style>
